package com.xiaoq.web;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;


public class DefaultMapper extends ObjectMapper {

	private static final long serialVersionUID = -4650823648091686648L;

	public DefaultMapper() {
		super();
		SimpleModule m = new SimpleModule("__defMapper", Version.unknownVersion());
		m.addSerializer(java.util.Date.class, new DateSerializer());
		m.addSerializer(java.sql.Date.class, new DateSerializer());
		m.addSerializer(java.sql.Timestamp.class, new TimestampSerializer());
		
		m.addDeserializer(java.util.Date.class, new DateDeserializer());
		m.addDeserializer(java.sql.Date.class, new DateDeserializer());
		m.addDeserializer(java.sql.Timestamp.class, new TimestampDeserializer());
		
		JsonInclude.Value v = JsonInclude.Value.construct(JsonInclude.Include.NON_EMPTY, JsonInclude.Include.NON_EMPTY);
		this.getSerializationConfig().withPropertyInclusion(v);
		
		this.registerModule(m);
	}

}
